local Rewarded = {}
function setromsize()
	local window = findWindow("Runes of Magic")
	setWindowPos(window, 500, 500, 100, 100, true)
end
function DailyNotesActivate(_arg)
	if RoMScript("DailyNotes") then
		RoMScript("DailyNotesFrame:Show()")
		cprintf(cli.lightblue,"Daily Notes addon instaled\n")
		if _arg then
			cprintf(cli.green,"AutoQuest Activated\n")
			RoMScript("DailyNotesAutoQuest:SetChecked(true)")
			RoMScript("DailyNotes.AutoQuest()")
			RoMScript("DailyNotes.AutoQuestSelectAll()")
		else
			cprintf(cli.red,"AutoQuest Deactivated\n")
			RoMScript("DailyNotes.AutoQuestClear()")
			RoMScript("DailyNotesAutoQuest:SetChecked(false)")
			RoMScript("DailyNotes.AutoQuest()")
		end
		RoMScript("DailyNotesFrame:Hide()")
	else
		print("Daily Notes addon not instaled")
	end
end

function belathis()
	for i = 1, 20 do 
		local npc
		npc = player:findNearestNameOrId("Bankelemos")
		teleport(npc.X,npc.Z,npc.Y)
		player:target_NPC("Bankelemos") 
	end
end

function HeadCount(inrange, printnames, ignoreFriends)
	local count = 0
	local Date = os.date("%x")
	local objectList = CObjectList();
	
	objectList:update();
	for i = 0,objectList:size() do
		local obj = objectList:getObject(i);
		if obj ~= nil and obj.Type == PT_PLAYER and obj.Address ~= player.Address and obj.Name ~= "<UNKNOWN>" and
		  (inrange == nil or inrange >= distance(player.X,player.Z,player.Y,obj.X,obj.Z,obj.Y) ) then
			if ignoreFriends ~= true or CPawn(obj.Address):isFriend() == false then
				count = count + 1
				if Rewarded[Date] == nil then
					Rewarded[Date] = {}
				end
				if not Rewarded[Date] then
					table.insert(Rewarded[Date], obj.Name)
				end
				if printnames == true then printf(obj.Name.."\t") end
			end
		end
	end
	if printnames == true then printf("\n") end

	return count
end

function PrintHeadCount()
	local Date = os.date("%x")
	for k, v in pairs(Rewarded[Date]) do
		print(k.." - "..v)
	end
end

function npcname()
   local objectList = CObjectList();
   objectList:update();
   local objSize = objectList:size()
   filename = getExecutionPath() .. "/logs/npc.txt";
   file, err = io.open(filename, "a+");
   if( not file ) then
      error(err, 0);
   end
   local target = player:getTarget()
      for i = 0,objSize do 
         obj = objectList:getObject(i);
         player:update()
         if obj.Type == 4 and obj.Name == target.Name then
			file:write(""..obj.Id.." = {"..obj.X..", "..obj.Z..", "..obj.Y.."}, -- "..obj.Name.."\n")
            --file:write("<NPC name=\""..obj.Name.."\"    id=\""..obj.Id.."\" x=\""..obj.X.."\"  z=\""..obj.Z.."\"  y=\""..obj.Y.."\" zoneid=\""..getZoneId().."\"   />\n")
         end
      end
   file:close();
end

------------------
-- send fusions --
------------------
local StatList = {
	-- KBN blue
	"Thunder X",	-- Stam_114/Matt_285
	"Illumine X",	-- Int_114/Matt_285
	"Elder X",		-- Int_114/Stam_114
	"Lumen X",		-- Wis_114/MaxHP_741
	"Genius X",		-- Int_114/Wis_114
	"Monk X",		-- Stam_114/Wis_114
	
	-- Bethonia blue
	"Illusion XI",
	"Illumine XI",
}
local mailingList1 = {
   "Faata",
   "Faatb",
   "Faatc",
   "Faatd",
   "Faate",
   "Faatf",
   "Faatg",
   "Faath"
   }  
local mailingList2 = {
   "Foota",
   "Footb",
   "Footc",
   "Footd",
   "Foote",
   "Footf",
   "Footg",
   "Footh"
   }
local mailingList3  = {
	"Lepaa",
	"Lepab",
	"Lepac",
	"Lepad",
	"Lepae",
	"Lepaf",
	"Lepag",
	"Lepah"
   }
local mailingList4  = {
	--"Pentrexil",
	"Penterxil",
	"Sinacilin",
	"Palitrex",
	--"Amoxicilin",
	--"Andol",
	--"Midol",
	--"Analgin",
	--"Karamija",
	--"Anabela",
	"Toxaris",
   }
   
function send_fusions(_mailinglist)
	if _mailinglist == "Faat" then
		mailingList = mailingList1
	elseif _mailinglist == "Foot" then
		mailingList = mailingList2
	elseif _mailinglist == "Lepa" then
		mailingList = mailingList3
	else
		printf("Wrong option specifided.\n")
	end
	
	for k,name in pairs(mailingList) do
		if (inventory:itemTotalCount("Fusion Stone") < 10) then
			RoMScript("UMMFrame:Hide()")
			UMM_TakeMail()
			if (inventory:itemTotalCount("Fusion Stone") < 10) then
				printf("Not enof fusion stones. "..name.." didn't got Fusions.\n")
				logInfo("Fusion Log", name.." didn't got Fusions.",true)
			else
				UMM_SendByNameOrId(name,{"Fusion Stone","Random Fusion Stone"}, 10)
				logInfo("Fusion Log", name.." got 10 Fusions.",true)
			end
		else
			UMM_SendByNameOrId(name,{"Fusion Stone","Random Fusion Stone"}, 10)
			logInfo("Fusion Log", name.." got 10 Fusions.",true)
		end
	end
end

function send_kbn(_mailinglist, _num)
	if _mailinglist == "Faat" then
		mailingList = mailingList1
	elseif _mailinglist == "Foot" then
		mailingList = mailingList2
	elseif _mailinglist == "Lepa" then
		mailingList = mailingList3
	elseif _mailinglist == "Lek" then
		mailingList = mailingList4
	else
		printf("Wrong option specifided.\n")
	end
	
	for k,name in pairs(mailingList) do
		if (40 > inventory:itemTotalCount(0)) then
			UMM_SendByFusedTierLevel(name, 5, _num)
			logInfo("Tiering Log", name.." got ".._num.." items.",true)
		else
			RoMScript("UMMFrame:Hide()")
			UMM_TakeMail()
			if (40 > inventory:itemTotalCount(0)) then
				UMM_SendByFusedTierLevel(name, 5, _num)
				logInfo("Tiering Log", name.." got ".._num.." items.",true)
			else
				printf("Not enof Blue items for "..name..".\n")
				logInfo("Tiering Log", name.." didn't got Items.",true)
			end
		end
	end
end

-- Open package's
function OpenSomething(_arg)
	repeat
		print("We Still need to open "..inventory:itemTotalCount(_arg))
		inventory:useItem(_arg)
	until inventory:itemTotalCount(_arg) == 0 or inventory:itemTotalCount(0) == 0
end

function gotonpc(_id)
	target = player:getTarget()
	if (not player.Mounted) then 
		player:mount();
	end
	RoMScript("NpcTrackFrame_QuickTrackByNpcID(".._id..")")
	repeat
		RoMScript("WorldMap_AutoMoveByNpcID(".._id..")")
		yrest(10000)
		player:target_NPC(_id)
	until (target.Id == _id) or RoMScript("SpeakFrame:IsVisible()") -- Target reached. Tracking stoped.
end

function tale()
	UMM_SendByFusedTierLevel(Tier5_2, 5)
end

function tale1(_num)
	UMM_SendByNameOrId(Tier5_2, Tier5_list, _num)
end

function Statname(num)
	inventory:update()
	item = inventory.BagSlot[num]
	statid = item.Stats[1].Id
	statname = item.Stats[1].Name
	print(statname)
	print(statid)
end

-- Sort me this
function Sort_for_me()
	local lines = {}
	local filename = getExecutionPath() .. "/logs/Sorted.txt"
	local file, err = io.open(filename, "r");
	if( not file ) then
		print("File not found");
		player:sleep()
	else
		local newlines = {}
		-- read the lines in table 'lines'
		for line in io.lines(filename) do
		  table.insert(lines, line)
		end
		-- sort
		table.sort(lines)
		table.concat(lines, "\n")
		print("Sorted");
		file:close()
		local newfile, err = io.open(filename, "w");
		newfile:write(table.concat(lines, "\n"))
		yrest(1000)
		newfile:close()
		print("writed");
	end
end

function talemsg()
	cprintf(cli.pink,"     ##############################\n")
	cprintf(cli.pink,"     ##")
	cprintf(cli.lightblue,"          Hello           ")
	cprintf(cli.pink,"##\n")
	cprintf(cli.pink,"     ##")
	cprintf(cli.yellow,"   Welcome to lolita's    ")
	cprintf(cli.pink,"##\n")
	cprintf(cli.pink,"     ##")
	cprintf(cli.lightblue,"  Minigame Daily waypoint ")
	cprintf(cli.pink,"##\n")
	cprintf(cli.pink,"     ##############################\n")
end